package com.controller.hystrix;

import com.hystrix.service.HelloService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
public class HystrixController {

    @Autowired
    private HelloService helloService;

    private static final Logger logger = LoggerFactory.getLogger(HystrixController.class);

    @RequestMapping(value = "/helloHystrix",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"} )
    public String helloHystrix(){
//        int sleepTime = new Random().nextInt(4000);
//        logger.info("sleepTime:"+sleepTime);
//        try {
//            Thread.sleep(sleepTime);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        return helloService.helloService();
    }

}
